
import utils from '../../utils/util';
var http=utils.http;
var star=utils.star;
var sliceTitle=utils.sliceTitle;
Page({
data: {

  },
   onConfirm(e){
     var value=e.detail.value;
     var url=`https://douban.uieee.com/v2/movie/search?q=${value}`;
     http(url,this.handleData);
   },
   handleData(res){
     var subjects=res.data.subjects;
     var movies=[];
     subjects.forEach(ele=>{
      var title=sliceTitle(ele.title);
      var id=ele.id;
      var average=ele.rating.average;
      var stars=star(ele.rating.stars);
      var imgUrl=ele.images.large;
      var temp={
          title,
          id,
          average,
          stars,
          imgUrl
      }
      movies.push(temp);
  })
  console.log(movies);
  this.setData({
      movies
  })
},    
})